package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.domain.StrategyEs;
import cn.wolfcode.wolf2w.business.api.domain.UserInfoEs;
import cn.wolfcode.wolf2w.business.repository.StrategyEsRepository;
import cn.wolfcode.wolf2w.business.repository.UserInfoEsRepository;
import cn.wolfcode.wolf2w.business.service.IStrategyEsService;
import cn.wolfcode.wolf2w.business.service.IUserInfoEsService;
import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.member.api.RemoteUserInfoService;
import cn.wolfcode.wolf2w.member.api.domain.UserInfo;
import cn.wolfcode.wolf2w.strategy.RemoteStrategyService;
import cn.wolfcode.wolf2w.strategy.entity.Strategy;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserInfoEsServiceImpl implements IUserInfoEsService {

    @Autowired
    private UserInfoEsRepository repository;

    @Autowired
    private RemoteUserInfoService remoteUserInfoService;


    @Override
    public void initUserInfoEs() {
        R<List<UserInfo>> r = remoteUserInfoService.list(SecurityConstants.INNER);
        List<UserInfoEs> esList = new ArrayList<>();
        List<UserInfo> list = r.getData();
        for (UserInfo userInfo : list) {
            UserInfoEs es = new UserInfoEs();
            BeanUtils.copyProperties(userInfo, es);
            esList.add(es);
        }
        repository.saveAll(esList);
    }
}
